package com.zy.portal.service.impl;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;

import com.zy.common.util.HttpClientUtil;
import com.zy.common.util.JsonUtils;
import com.zy.common.util.TaotaoResult;
import com.zy.pojo.TbOrder;
import com.zy.portal.pojo.Item;
import com.zy.portal.pojo.SearchResult;
import com.zy.portal.service.OrderService;

@Service
public class OrderServiceImpl implements OrderService {
	/**
	 * solr搜索基础url
	 */
	@Value("${SEARCH_BASEBYID_URL}")
	private String SEARCH_BASEBYID_URL;
	
	TbOrder tbOrder;
	/**
	 * 结算
	 */
	@Override
	public List<Item> showOrder(String urls) {
		List<Item> arrayList = new ArrayList<Item>();
		HashMap<String, String> param = new HashMap<>();
		param.put("page","1");
		if(urls.contains(",")) {
			String[] split = urls.split(",");
			for (String s : split) {
				// 创建所需的map对象
				//远程调用
				param.put("q", s);
				String json = HttpClientUtil.doGet(SEARCH_BASEBYID_URL, param);
				TaotaoResult taotaoResult = TaotaoResult.formatToPojo(json, Item.class);
				if(taotaoResult.getStatus()==200) {
					Item data = (Item) taotaoResult.getData();
					arrayList.add(data);
				}
			}
			return arrayList;
		}else {
			param.put("q", urls);
			String json = HttpClientUtil.doGet(SEARCH_BASEBYID_URL, param);
			TaotaoResult taotaoResult = TaotaoResult.formatToPojo(json, Item.class);
			Item data = (Item) taotaoResult.getData();
			arrayList.add(data);
			return arrayList;
		}
	}

}
